package com.manage.competition.service.impl;

import com.manage.competition.entity.AnswerPaper;
import com.manage.competition.mapper.AnswerPaperMapper;
import com.manage.competition.repository.AnswerRepository;
import com.manage.competition.service.IAnswerPaperService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 13:45 2019/4/9
 * @Description:
 */
@Service
public class AnswerPaperServiceImpl implements IAnswerPaperService {

    @Autowired
    private AnswerPaperMapper answerPaperMapper;

    @Autowired
    private AnswerRepository answerRepository;

    @Override
    public int insert(AnswerPaper answerPaper) {
        answerPaper.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        answerPaper.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return answerPaperMapper.insert(answerPaper);
    }

    @Override
    public AnswerPaper findByQuestionIdAndUserId(long userId,long questionId) {
        return answerRepository.findByUserIdAndQuestionsId(userId, questionId);
    }

    @Override
    public int update(AnswerPaper answerPaper) {
        return answerPaperMapper.updateByPrimaryKeySelective(answerPaper);
    }

    @Override
    public List<AnswerPaper> findByCompetitionAndUserId(long competitionId, long userId) {

        return answerRepository.findByCompetitionIdAndUserId(competitionId,userId);
    }


}
